package test2;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;

public class DemoFile {
    public static void main(String[] args) throws IOException {

        File directory = new File("");//参数为空

        String courseFile = directory.getCanonicalPath() ;
        System.out.println(courseFile);
        File file=new File(courseFile);
        HashMap <String,Integer> hm=new HashMap<>();
        System.out.println(file.length());
         getCount(file,hm);
         System.out.println(hm);


    }

    private static void getCount(File file, HashMap<String, Integer> hm) {
        File[] file1=file.listFiles();
        for (File listFile : file1) {
            if(listFile.isFile()){
                //判断是否是文件
                String listFileName = listFile.getName();
                String[] split = listFileName.split("\\.");
                if(split.length==2){
                    String name=split[1];
                    if(hm.containsKey(name)){
                        Integer integer = hm.get(listFileName);
                        if(null!=integer) {
                            integer++;
                        }else {
                            integer=1;
                        }
                        hm.put(name,integer);

                    }else{
                        hm.put(name,1);
                    }
                }




            }else{
                //文件夹
                getCount(listFile, hm);
            }
            
        }


    }
}
